<?php
//header("Content-type:text/html;charset=utf-8");
$act = $_REQUEST['act'];
$username = $_POST['username'];
if(!empty($_POST['password'])){
	$password = md5($_POST['password']);
}else{
	$password=NULL;
}
mysql_connect('localhost','root','');
mysql_select_db('shopimooc');
mysql_set_charset('utf-8');
if($act == 'reg'){
	$sql = "INSERT INTO imooc_admin (username,password) VALUES('{$username}','{$password}')";
	//echo $sql;die();
	$res = mysql_query($sql);
	if($res){
		echo "注册成功！3秒后跳转到登录页面";
		echo "<meta http-equiv='Refresh' content='3;url=login.html'>";
	}else{
		echo "注册失败！1秒后跳转到注册页面";
		echo "<meta http-equiv='Refresh' content='1;url=reg.html'>";
	}
}else if($act == 'login1'){
	$sql = "select * from imooc_admin where username='{$username}' and password='{$password}'";
	//echo $sql;die();
	$res = mysql_fetch_assoc(mysql_query($sql));
	if($res){
		echo "登录成功！3秒后跳转到百度页面";
		echo "<meta http-equiv='Refresh' content='3;url=http://www.baidu.com'>";
	}else{
		echo "登录失败！1秒后跳转到注册页面";
		echo "<meta http-equiv='Refresh' content='1;url=reg.html'>";
	}

}